//
//  MoviesCell.m
//  music
//
//  Created by LT on 2019/4/24.
//  Copyright © 2019 liu. All rights reserved.
//

#import "MoviesCell.h"
#import "MoviesModel.h"
#import "Masonry.h"
@implementation MoviesCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        
        
        self.layer.shadowColor=[UIColor blackColor].CGColor;
        self.layer.shadowOpacity=0.5;
        self.layer.shadowOffset=CGSizeMake(0, 0);
        self.layer.cornerRadius=10;
        
        [self addSubview:self.dyImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.introduceLabel];
        [self addSubview:self.scoreLabel];
    }
    return self;
}



//电影的图片
-(YYAnimatedImageView*)dyImageView{
    if (_dyImageView==nil) {
        _dyImageView=[[YYAnimatedImageView alloc]init];
        [self addSubview:_dyImageView];
        [_dyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(10);
            make.left.equalTo(self).offset(10);
            make.size.mas_equalTo(CGSizeMake(self.frame.size.height*0.8, self.frame.size.height*0.8));
        }];
        _dyImageView.backgroundColor=UIColor.redColor;
        NSURL *URL = [NSURL URLWithString:@""];
        
        [_dyImageView yy_setImageWithURL:URL placeholder:nil options:YYWebImageOptionSetImageWithFadeAnimation progress:^(NSInteger receivedSize, NSInteger expectedSize) {
            
            // 计算进度
            float progress = (float)receivedSize/expectedSize;
            NSLog(@"打印下载进度%f",progress);
            
        } transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) {
            
            // 可以额外处理图片在返回 : 截取中心点周围100x100的范围
            //        return [image yy_imageByResizeToSize:CGSizeMake(100, 100) contentMode:UIViewContentModeCenter];
            
            // 返回原始图片
            return image;
            
        } completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
            
            // 测试 : 是否是从磁盘加载的
            if (from == YYWebImageFromDiskCache) {
                NSLog(@"磁盘缓存加载");
            }
        }];
    }
    return _dyImageView;
}

//电影名称
-(UILabel *)titleLabel {
    if (_titleLabel ==nil) {
        _titleLabel=[[UILabel alloc]init];
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(20);
            make.left.equalTo(self.dyImageView.mas_right).offset(20);
            make.size.mas_equalTo(CGSizeMake(self.frame.size.width*0.2, 20));
        }];
        _titleLabel.font=[UIFont systemFontOfSize:20];
        _titleLabel.text=@"aaa";
    }
    return _titleLabel;
}

//介绍
-(UILabel *)introduceLabel{
    if (_introduceLabel==nil) {
        _introduceLabel=[[UILabel alloc]init];
        [self addSubview:_introduceLabel];
        [_introduceLabel mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
            make.left.equalTo(self.dyImageView.mas_right).offset(20);
            make.size.mas_equalTo(CGSizeMake(self.frame.size.width*0.45,self.frame.size.height*0.5 ));
        }];
        
        _introduceLabel.text=@"这是一些电影的介绍这是一些电影的介绍这是一些电影的介绍这是一些电影的介绍这是一些电影的介绍";
        _introduceLabel.numberOfLines=0;
        _introduceLabel.font=[UIFont systemFontOfSize:15];
        _introduceLabel.textColor=[UIColor colorWithRed:0/255 green:0/255 blue:0/255 alpha:0.4];
    }
    return _introduceLabel;
}

//排行数字
-(UILabel *)rankingLabel{
    if (_rankingLabel==nil) {
        _rankingLabel=[[UILabel alloc]init];
        [self addSubview:_rankingLabel];
        [_rankingLabel mas_makeConstraints:^(MASConstraintMaker *make){
            make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
            make.left.equalTo(self.dyImageView.mas_right).offset(20);
            make.size.mas_equalTo(CGSizeMake(self.frame.size.width*0.2, 30));
        }];
        _rankingLabel.backgroundColor=[UIColor redColor];
        _rankingLabel.text=@"asfbksjygf;isGUF;Iugdf;isugFD;Iyugsdf;iu";
    }
    return  _rankingLabel;
}



//P评分
-(UILabel *)scoreLabel{
    if (_scoreLabel==nil) {
        
        UIView *view=[[UIView alloc]init];
        [self addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make){
            make.left.equalTo(self.introduceLabel.mas_right).offset(5);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(30, 40));
        }];
        view.backgroundColor=[UIColor yellowColor];
        //v.layer.masksToBounds=YES;这行去掉
        view.layer.cornerRadius=5;
        view.layer.shadowColor=[UIColor blackColor].CGColor;
        view.layer.shadowOffset=CGSizeMake(0, 0);
        view.layer.shadowOpacity=0.3;
        view.layer.shadowRadius=5;
        [self addSubview:view];
        
        
        _scoreLabel=[[UILabel alloc]init];
        [self addSubview:_scoreLabel];
        [_scoreLabel mas_makeConstraints:^(MASConstraintMaker *make){
            make.left.equalTo(self.introduceLabel.mas_right).offset(5);
            make.centerY.equalTo(self).offset(0);
            make.size.mas_equalTo(CGSizeMake(30, 40));
        }];
        _scoreLabel.backgroundColor=[UIColor yellowColor];
        _scoreLabel.text=@"19";
        _scoreLabel.textAlignment=NSTextAlignmentCenter;
        _scoreLabel.textColor=[UIColor blackColor];
        _scoreLabel.layer.cornerRadius = 5;
        _scoreLabel.layer.masksToBounds=YES;
    }
    return _scoreLabel;
}


//---------------设定cell 之间的 高度

- (void)setFrame:(CGRect)frame{  //顶部的距离
    frame.origin.x=5;
    frame.origin.y+=20;
    frame.size.width=365;
    frame.size.height = 145;//cell 之间相距的高度
    [super setFrame:frame];
    
}



-(void)setDy:(MoviesModel *)dy{
    _dy=dy;
    self.dyImageView.yy_imageURL=[NSURL URLWithString:dy.images];
    self.titleLabel.text=dy.title;
    self.introduceLabel.text=dy.introduce;
    self.scoreLabel.text=dy.scrore;
}


@end
